package com.melody.android.logic.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MySQLiteOpenHelper extends SQLiteOpenHelper {

    /**
     * 构造方法
     * @param context 上下文实例
     */
    public MySQLiteOpenHelper(Context context) {
        super(context, "melody.db", null, 1);
    }

    /**
     * 数据库第一次执行时调用该方法(建表语句)
     * @param sqLiteDatabase 上下文实例
     */
    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        // 用户表
        sqLiteDatabase.execSQL("CREATE TABLE user (" +
                "Uid INTEGER PRIMARY KEY AUTOINCREMENT," +
                "account VARCHAR(20) UNIQUE NOT NULL," +
                "password VARCHAR(20) NOT NULL," +
                "singer VARCHAR(20) NOT NULL," +
                "song VARCHAR(20) NOT NULL" +
                ")");

        // 自定义歌单表
        sqLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS songList (" +
                "SLid INTEGER PRIMARY KEY AUTOINCREMENT," +
                "name TEXT UNIQUE NOT NULL," +
                "num INTEGER NOT NULL" +
                ")");
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {

    }

}
